<template>
    <div>
        <h2>科室信息添加</h2>
        <table class="table">
            <tbody>
                <tr>
                    <td>科室名称</td>
                    <td><input type="text" v-model="data.name" name="" id=""></td>
                </tr>
                <tr>
                    <td>科室人数</td>
                    <td><input v-model="data.pnum" type="text" name="" id=""></td>
                </tr>
                <tr>
                    <td>科室介绍</td>
                    <td><textarea name="" id="" v-model="data.jieshao"></textarea></td>
                </tr>
                <tr>
                    <td>创建时间</td>
                    <td>
                        <input v-model="data.createdate" type="date" name="" id="">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter();

const data=ref({
  "id": 0,
  "name": "",
  "pnum": 0,
  "jieshao": "",
  "createdate": "",
  "del": false,
  "people": "string",
  "adddate": "2025-02-18T07:42:37.659Z"
})
const add=()=>{
    axios.post('https://localhost:7260/api/KeShi/AddKeshi',data.value).then(res=>{
        if(res.data>0){
            alert('添加成功');
            router.push('/showks');
        }
        if(res.data==-1){
            alert('科室名称不能重复');
            return;
        }
    })
}
</script>

<style scoped>

</style>